import { defineStore } from 'pinia'

export const useAppStore = defineStore('app', {
  state: () => ({
    sidebar: {
      opened: true
    },
    device: 'desktop',
    theme: 'light'
  }),

  actions: {
    toggleSidebar() {
      this.sidebar.opened = !this.sidebar.opened
    },
    closeSidebar() {
      this.sidebar.opened = false
    },
    setDevice(device) {
      this.device = device
    },
    setTheme(theme) {
      this.theme = theme
    }
  },

  persist: {
    enabled: true,
    strategies: [
      {
        key: 'app-settings',
        storage: localStorage,
        paths: ['theme', 'sidebar.opened']
      }
    ]
  }
})